package com.fms.gui.existingSheets;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import javax.swing.table.AbstractTableModel;

import com.fms.model.domain.IExistingFlowSheets;

public class ExistingSheetModel extends AbstractTableModel
{
	private IExistingFlowSheets	sheets;
	private static final int COLUMN_COUNT = 5;
	
	private static final int DATE_COLUMN = 0;
	private static final int EMAILED = 2;
	

	public ExistingSheetModel(IExistingFlowSheets _sheets)
	{
		this.sheets = _sheets;
	}

	/**
	 * 
	 */
	private static final long	serialVersionUID	= -550231779862783176L;

	@Override
	public int getColumnCount()
	{
		return COLUMN_COUNT;
	}

	@Override
	public int getRowCount()
	{
		return sheets.getFlowSheets().size();
	}
	
	
	@Override
	  public boolean isCellEditable(int rowIndex, int columnIndex)
	  {
	    return true;
	  }
	@Override
	public Object getValueAt(int rowIndex, int columnIndex)
	{
		rowIndex = this.getRowCount() - 1 - rowIndex;
		
		if(columnIndex == DATE_COLUMN)
		{
			Calendar time = sheets.getFlowSheets().get(rowIndex).getDate();
			Calendar now = Calendar.getInstance();
			if(	time.get(Calendar.DAY_OF_MONTH) == now.get(Calendar.DAY_OF_MONTH) &&
				time.get(Calendar.MONTH) == now.get(Calendar.MONTH) &&
				time.get(Calendar.YEAR) == now.get(Calendar.YEAR) )
					
			{
				return "Today";
			}
			else
			{
				return new SimpleDateFormat("EEEE").format(time.getTime());
				
			}
		}
		if(columnIndex == EMAILED)
		{
			if(sheets.getWasEmailed(rowIndex))
			{
				return "Emailed.";
			}
			else
			{
				return "Not emailed.";
			}
		}
		if(columnIndex == 1)
		{
			Calendar time = sheets.getFlowSheets().get(rowIndex).getDate();
			
			return new SimpleDateFormat("MMMM d, yyyy").format(time.getTime());
		}

//		
		return sheets.getFlowSheets().get(rowIndex);
		
	}

}
